import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:my_app/app/widgets/custom_title_widget.dart';

/// dialog_page.dart
///
/// Created by fuchuanwei on Thu Feb 23 2023.
///
/// Description:对话框页面
///
class DialogPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('Smart Dialog')),
        body: ListView(
          padding: EdgeInsets.all(10.0),
          children: [
            toastDemo(),
            SizedBox(height: 20),
            loadingDemo(),
            SizedBox(height: 20),
            dialogDemo(),
            SizedBox(height: 20),
            attachDemo(),
            SizedBox(height: 20),
            notifyDemo(),
          ],
        ));
  }

  Widget toastDemo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleWidget(
          title: 'Toast',
        ),
        SizedBox(
          height: 10.0,
        ),
        Wrap(
          spacing: 10.0,
          children: [
            OutlinedButton(
              onPressed: () {
                SmartDialog.showToast("Toast!!!");
              },
              child: Text('default'),
            ),
          ],
        ),
      ],
    );
  }

  Widget loadingDemo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleWidget(title: 'Loading'),
        SizedBox(
          height: 10.0,
        ),
        Wrap(
          spacing: 10.0,
          children: [
            OutlinedButton(
              onPressed: () async {
                SmartDialog.showLoading(msg: 'loading...');
                await Future.delayed(Duration(seconds: 2));
                SmartDialog.dismiss();
              },
              child: Text('default'),
            ),
          ],
        )
      ],
    );
  }

  Widget dialogDemo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleWidget(title: 'Dialog'),
        SizedBox(
          height: 10.0,
        ),
        Wrap(
          spacing: 10.0,
          children: [
            OutlinedButton(
              onPressed: () {
                SmartDialog.show(
                  builder: (ctx) => Container(
                    height: 80,
                    width: 180,
                    decoration: BoxDecoration(
                      color: Colors.black,
                      borderRadius: BorderRadius.circular(10),
                    ),
                    alignment: Alignment.center,
                    child: Text(
                      'default dialog',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                );
              },
              child: Text('default'),
            ),
          ],
        )
      ],
    );
  }

  Widget attachDemo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleWidget(title: 'Attach'),
        SizedBox(
          height: 10.0,
        ),
        Wrap(
          spacing: 10.0,
          children: [
            Builder(builder: (ctx) {
              return OutlinedButton(
                onPressed: () {
                  SmartDialog.showAttach(
                    targetContext: ctx,
                    builder: (_) => Container(
                      width: 180.0,
                      height: 80.0,
                      decoration: BoxDecoration(color: Colors.red),
                      child: Text('我是一个Attach'),
                    ),
                  );
                },
                child: Text('default'),
              );
            })
          ],
        )
      ],
    );
  }

  Widget notifyDemo() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleWidget(title: 'Notify'),
        SizedBox(
          height: 10.0,
        ),
        Wrap(
          spacing: 10.0,
          children: [
            OutlinedButton(
              onPressed: () {
                SmartDialog.showNotify(
                    msg: "success!", notifyType: NotifyType.success);
              },
              child: Text('success'),
            ),
            OutlinedButton(
              onPressed: () {
                SmartDialog.showNotify(
                    msg: "failure!", notifyType: NotifyType.failure);
              },
              child: Text('failure'),
            ),
            OutlinedButton(
              onPressed: () {
                SmartDialog.showNotify(
                    msg: "warning!", notifyType: NotifyType.warning);
              },
              child: Text('warning'),
            ),
            OutlinedButton(
              onPressed: () {
                SmartDialog.showNotify(
                    msg: "alert!", notifyType: NotifyType.alert);
              },
              child: Text('alert'),
            ),
            OutlinedButton(
              onPressed: () {
                SmartDialog.showNotify(
                    msg: "error!", notifyType: NotifyType.error);
              },
              child: Text('error'),
            )
          ],
        )
      ],
    );
  }
}
